package jxtend.processor.utils;

import java.lang.reflect.Array;

public final class ArrayUtils {

	public static <T> T[] removeFromArray(Class<T> itemType, T[] originalArray, int index) {
		assert (originalArray != null) && (originalArray.length > 0);

		@SuppressWarnings("unchecked") T[] result = (T[]) Array.newInstance(itemType, originalArray.length - 1);

		if (result.length == 0) {
			return result;
		}

		if (index > 0) {
			System.arraycopy(originalArray, 0, result, 0, index);
		}

		if ((index + 1) < originalArray.length) {
			System.arraycopy(originalArray, index + 1, result, index, originalArray.length - index - 1);
		}

		return result;
	}

	private ArrayUtils() {
		// Utility class
	}
}
